/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.gui.controls.kleurschema;

import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URI;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;

/**
 *
 * @author Gonyo
 */
public class Kleurenschemas {

    private Logger logger = Logger.getLogger(Kleurenschemas.class);
    public Color ww3Kleur = new Color(255, 0, 102);
    public Color ww2Kleur = new Color(204, 153, 255);
    public Color lw3Kleur = new Color(0, 102, 255);
    public Color lw2Kleur = new Color(51, 255, 153);
    public Color MiddenKleur = new Color(255, 255, 102);
    public Color spelbordKleur = new Color(0, 153, 153);
    public Color plankKleur = new Color(0, 153, 153);
    public Color blokjeKleur = new Color(255, 255, 204);
    public Color gevalideerdBlokjeKleur = Color.LIGHT_GRAY;
    public Color blankBlokjeKleur = new Color(255, 0, 0);
    public Color selecteerKleur = new Color(153, 204, 255);
    public Color fontBlokjeKleur = new Color(0, 153, 153);
    public Color gevalideerdFontBlokjeKleur = new Color(100, 100, 100);
    public Color fontSpelbordKleur = Color.BLACK;
    public Color[] kleuren = new Color[14];
    private static Kleurenschemas instance = new Kleurenschemas();
    private String file = "MijnStijl";
    private String kleurschemapad;

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public static Kleurenschemas getInstance() {
        return instance;
    }

    private Kleurenschemas() {
        //bundle = ResourceBundle.getBundle("woordspelletjes");
        try{
            setKleurschemapad(getClass().getResource("").getFile().split("ScrabbleProject.jar")[0]);
        }catch(Exception ex){
      //wanneer het prog niet al jar opgestart wordt}
            setKleurschemapad(getClass().getResource("").getFile());
  }
        laadKleuren(file);
    }

    public static void main(String[] args) {
        String line = "a;b;;d";

        String values[] = line.split(";", 4);

        for (int i = 0; i < values.length; i++) {
            System.out.println(values[i]);
        }
    }

    public void laadKleuren(String file) throws NumberFormatException {
        //String s = bundle.getString("kleurschema_" + file);
        
        try {
            logger.info("LAADKLEUREN_____________________");
            logger.info(getClass().getResource("").getFile());
            logger.info(getClass().getResource("").getFile().split("ScrabbleProject.jar")[0]);
            //String s = getClass().getResource("").getFile().split("ScrabbleProject.jar")[0] + file + ".conf";
            URI uri = new URI(getKleurschemapad() + file + ".conf");
            String s = uri.getPath();
          
            
            BufferedReader in = new BufferedReader(new FileReader(s));
            String str;
            int i = 0;
            while ((str = in.readLine()) != null) {
                //System.out.println(str);
                String[] tempS = str.split(";", 4);

                //System.out.println(Integer.parseInt(tempS[1]) + " " + Integer.parseInt(tempS[2]) + " " + Integer.parseInt(tempS[3]));
                kleuren[i] = new Color(Integer.parseInt(tempS[1]), Integer.parseInt(tempS[2]), Integer.parseInt(tempS[3]));
                i++;
            }
            if (kleuren.length == 14) {
                ww3Kleur = kleuren[0];
                ww2Kleur = kleuren[1];
                lw3Kleur = kleuren[2];
                lw2Kleur = kleuren[3];
                MiddenKleur = kleuren[4];
                spelbordKleur = kleuren[5];
                plankKleur = kleuren[6];
                blokjeKleur = kleuren[7];
                gevalideerdBlokjeKleur = kleuren[8];
                blankBlokjeKleur = kleuren[9];
                selecteerKleur = kleuren[10];
                fontBlokjeKleur = kleuren[11];
                gevalideerdFontBlokjeKleur = kleuren[12];
                fontSpelbordKleur = kleuren[13];
            }
            in.close();
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }

    public String getKleurschemapad() {
        return kleurschemapad;
    }

    public void setKleurschemapad(String kleurschemapad) {
        this.kleurschemapad = kleurschemapad;
    }
}
